<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>  
<!DOCTYPE html>
<html>
<head>
<title>菜单管理列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="decorator" content="old" />

<link href="${ctxStatic}/treeTable/themes/vsStyle/treeTable.min.css" rel="stylesheet" type="text/css" />
<script src="${ctxStatic}/treeTable/jquery.treeTable.min.js" type="text/javascript"></script>

</head>
<body>
	<div class="boxcontent" style="margin: 0;">
		<div class="content" style="margin: 0;">
			<form:form id="searchForm" modelAttribute="menu" action="${ctx}/sys/menu/list" method="post" class="form-search">
				<!-- <div class="search-bar">
					<ul class="clearfix">
						<li>
							<span>名称：</span>
							<input type="text" class="form-control">
						</li>
						<li>
							<span>链接：</span>
							<input type="text" class="form-control">
						</li>
					</ul>
					<div id="btn_search" class="search-btn">查询</div>
					<script type="text/javascript">
						$(function(){
							$(".search-bar ul li").each(function(){
								var spanWidth = $(this).find("span").width();
								$(this).find(".form-control").width(230-20-spanWidth);	
								$(this).children(".input-append").find(".required").width(230-20-36+1-spanWidth);	
								var barHeight = $(".search-bar").height();
								$(".search-btn").css("line-height", barHeight+"px");
							});
						})
					</script>
				</div> -->
				<div id="btn_search" class="search-btn" style="display: none">查询</div>
				<div class="btns">
				<c:set var="canEdit" value="false"></c:set>
				<%--<shiro:hasPermission name="sys:menu:create"> --%>
					<button type="button" class="btn-custom" onclick="createByTitle('/sys/menu/form','新增菜单',false)">新增</button>
					<button type="button" class="btn-custom" onclick="addNextMenu('/sys/menu/form','添加下级菜单',1000,600,'10px',false)">添加下级菜单</button>					
				<%--</shiro:hasPermission>--%>
				<shiro:hasPermission name="sys:menu:edit">
				    <c:set var="canEdit" value="true" />
					<button type="button" class="btn-custom" onclick="modifyByMenu('/sys/menu/form','修改')">修改</button>
				</shiro:hasPermission>
				<shiro:hasPermission name="sys:menu:delete">
				    <button type="button" class="btn-custom btndelete" data-deleteurl='${ctx}/sys/menu/delete'  onclick="top.$.jBox.confirm('真的要删除吗？','系统提示',deleteData)">删除</button>
				</shiro:hasPermission>
					<button type="button" class="btn-custom" onclick="exportData('${ctx}/sys/menu/export')">导出</button>
				</div>
			</form:form>
			<div class="tbbox firsttdCenter">
				<div class="boxthead">
		           <div class="autobox">
		           		<table cellpadding="0" cellspacing="0" class="table table-bordered tbhead">
			              <thead>
		              		<tr>
			                   <th style="width:30px;"><input type="checkbox" class="checkall"/></th>
			                   <th style="width:250px;">名称</th>
			                   <th style="width:200px;">链接</th>
			                   <th style="width:60px;">排序</th>
			                   <th style="width:60px;">可见</th>
			                   <th style="width:200px;">权限标识</th>
			                </tr>
			              </thead>
			           </table>
		           </div>
		       </div>
			   <div class="boxbody ">
		            <table id="treeTable" cellpadding="0" cellspacing="0" class="table table-bordered tbbody">
		                <tbody>
		                	<c:forEach items="${list}" var="menu">
	                	    	<tr id="${menu.id}" pId="${menu.parent.id ne '1'?menu.parent.id:'0'}">
	                	    		<td style="width:30px;">
										<input type="hidden" id="id" value="${menu.id}" />
										<input type="checkbox" data-param="id=${menu.id}" />
									</td>
	                				<td style="width:250px;" nowrap>
										<i class="icon-${not empty menu.icon?menu.icon:' hide'}"></i>
										<c:if test="${canEdit == true}">
										   <a href="javascript:void(0);" onclick="opencreateWindow('/sys/menu/form?id=${menu.id}','修改菜单',1000,600,'10px',false)">${menu.name}</a>
										</c:if>
										<c:if test="${canEdit != true}">
										   ${menu.name}
										</c:if>
									</td>
									<td style="width:200px;" title="${menu.href}">${fns:abbr(menu.href,30)}</td>
				                    <td style="width:60px; text-align: center;">
				                    	<input type="hidden" name="ids" value="${menu.id}"/>
										<input name="sorts" type="text" value="${menu.sort}" style="width:50px; height: 22px !important; margin:0;padding:0;text-align:center; border-radius: 4px;">
				                    </td>
				                   <td style="width:60px;">${menu.isShow eq '1'?'显示':'隐藏'}</td>
				                   <td style="width:200px;" title="${menu.permission}">${fns:abbr(menu.permission,30)}</td>
	                			</tr>
		                	</c:forEach>
		                </tbody>
		            </table>
		        </div>
			</div>
		</div>
	</div>
	<jsp:include page="/WEB-INF/views/include/pageJs.jsp" />
	
	<script type="text/javascript">
		$(document).ready(function() {
			$("#treeTable").treeTable({expandLevel : 3,column:1}).show();
			
		    $("#btn_search").click(function () { 
		    	$("#searchForm").submit();
		    }); 
		});
		
	
		function addNextMenu(url, istrue) {
			var isclose=istrue==true?true:false;
			var checkboxs=$(".tbbody").find("input[type=checkbox]:checked");
			if(checkboxs.length>1){
				top.$.jBox.tip("不能多条数据同时修改",""); 
				return false;
			}
			if(checkboxs.length==0){
				top.$.jBox.tip("请选择一条修改的数据",""); 
				return false;
			}
			
			//获取选中的tr
			var tr = $(".tbbody").find("input[type=checkbox]:checked").parents("tr");
			var id = tr.find("#id").val();
			
			url=url+"?parent.id="+id;
			opencreateWindow1(url,'添加下级菜单',1000,600,'10px',isclose);
		}
		
		//修改
		function modifyByMenu(url,title){
			
			var checkboxs=$(".tbbody").find("input[type=checkbox]:checked");
			if(checkboxs.length>1){
				top.$.jBox.tip("不能多条数据同时修改",""); 
				return false;
			}
			if(checkboxs.length==0){
				top.$.jBox.tip("请选择一条修改的数据",""); 
				return false;
			}
			var tr = $(".tbbody").find("input[type=checkbox]:checked").parents("tr");
			var id = tr.find("#id").val();
			
			url=url+"?id="+id;
			opencreateWindow(url,title,1000,600,'10px',false);
		}
		
		function opencreateWindow1(url, title, width, height, topValue,isclose) {
			url = "iframe:" + "${ctx}/" + url;
			topValue = (topValue == '' ? '10%' : '10px');
			
			var buttons=isclose==true?{"关闭":"cancel"}:{};
			top.$.jBox.open(url, title, width, height,
				{
					persistent : true,
					top : topValue,
					buttons : buttons,
					opacity: 0.5,
					submit : function(v, h, f) {
						/*  点击窗口按钮后的回调函数，返回true时表示关闭窗口，参数有三个，
						 v表示所点的按钮的返回值，
						 h表示窗口内容的jQuery对象，
						 f表示窗口内容里的form表单键值
						 */
					},
					closed : function() {
						//	$("#btn_search").click();
					}
				});
		}
		
	</script>
</body>
</html>